#ifndef EJBASESET_H
#define EJBASESET_H

#include <QMenu>
#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
#include <QGroupBox>
#include <QMainWindow>

#include <QTableView>
#include <QSqlTableModel>

#define EJ_DEF_GROUP(name) QGroupBox *name##GroupBox = nullptr;  \
                     QTableView     *name##View = nullptr;      \
                     QSqlTableModel *name##Model = nullptr;

#define EJ_CRE_GROUP(name, boxName, parent, table) name##GroupBox = new QGroupBox(boxName, parent);\
                     name##Model = new QSqlTableModel(name##GroupBox);   \
                     name##Model->setTable(table);                       \
                     name##Model->select();                              \
                     name##View = new QTableView(name##GroupBox);        \
                     name##View->setModel(name##Model);                  \
                     auto name##grid = new QGridLayout;                   \
                     name##grid->addWidget(name##View, 0, 0, 5, 1);      \
                     name##GroupBox->setLayout(name##grid);

#define EJ_SET_GROUP(name)name##GroupBox->setStyleSheet(g_groupBoxStyle);\
                     name##View->setStyleSheet(g_tableViewStyle);

struct AddViewColumnEvent
{
    int     attrType;  /*0全局, 1基础*/
    int     isIfc;     /*0否  1是*/
    QString columnName;
};


class EJAttrSet : public QMainWindow
{
    Q_OBJECT
public:
    explicit EJAttrSet(QWidget *parent = 0);

signals:

public slots:
    void OnGlobalAdd();
    void OnGlobalDel();
    void OnGlobalHeaderClicked(int);

    void OnBaseAdd();
    void OnBaseDel();
    void OnBaseHeaderClicked(int);

    void OnGlobalPopMenu(QPoint);
    void OnBasePopMenu(QPoint);

    void OnSaveGlobalData();
    void OnSaveBaseData();

    void OnAddCol();
    void OnAddViewColumn(AddViewColumnEvent *event);

    void OnEffectedChang(bool check, const QModelIndex index);
protected:

private:
    /**
     * @brief CreateColumn
     * @param view
     * @param model
     * @param name
     * @param inf       0 被影响   1影响
     * @param deleGate
     */

    void CreateColumn(QTableView *view, QSqlTableModel *model, const QString &name, int inf = false, QAbstractItemDelegate *deleGate = nullptr);

private:
    QMenu       *m_popGlobalMenu = nullptr;
    QMenu       *m_popBaseMenu = nullptr;

    EJ_DEF_GROUP(m_base)
    EJ_DEF_GROUP(m_global)

};

class EJAddViewColumn : public QDialog
{
    Q_OBJECT
public:
    enum AddViewColumnType
    {
        GLOBAL,
        BASE
    };

    EJAddViewColumn(AddViewColumnType type = GLOBAL, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());

private:


signals:
    void addViewColumn(AddViewColumnEvent *event);
public slots:
    void OnConfirm();
    void OnCancel();
private:
    QComboBox *m_attrTypeBox;
    QLineEdit *m_attrNameEdt;
    QComboBox *m_attrInfBox;
};


#endif // EJBASESET_H
